{% extends 'base.html' %}
{% load comments %}
{% load signup_extras %}

{% block title %}{{constituency.name}}{% endblock %}
{% block section %}constituency{% endblock %}

{% block extra-head %}
<link rel="stylesheet" type="text/css"  media="screen" href="{{ MEDIA_URL }}comments/comments.css" />
<link rel="stylesheet" type="text/css"  media="screen" href="{{ MEDIA_URL }}issues/issues.css" />
<link rel="stylesheet" type="text/css"  media="screen" href="{{ MEDIA_URL }}tasks/tasks.css" />
<link rel="stylesheet" type="text/css"  media="screen" href="{{ MEDIA_URL }}constituency/constituency.css" />
{% endblock %}

{% block js %}
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

    <script>       
        function show_tab(tab_id, switcher_id)
        {
            $('.tab').hide();
            $('#'+tab_id).show();
            $('.tabswitcher li').removeClass('active');
            $('#'+switcher_id).addClass('active');
        }

        $(document).ready(function () {
            if(window.location.hash == "#issues")
            {
                show_tab('tab-2', 'switcher2');
            }
            else if(window.location.hash == "#email")
            {
                show_tab('tab-3', 'switcher3');
            }
            else if(window.location.hash == "#questions")
            {
                show_tab('tab-4', 'switcher4');
            }
            else
            {
                
            }
        });
    </script>
{% endblock %}

{% block content %}
<ul class="tabswitcher">
    <li id="switcher1" class="first active"><a href="#" onclick="show_tab('tab-1', 'switcher1')">{{ constituency.name }} information</a></li>
{% if constituency.refinedissue_set.count %}
    <li id="switcher4" class="inactive"><a href="#questions" onclick="show_tab('tab-4', 'switcher4')">Local questions</a></li>
{% endif %}
    <li id="switcher2" class="inactive"><a href="#issues" onclick="show_tab('tab-2', 'switcher2')">Local issues</a></li>
{% if request.user.is_superuser %}
    <li id="switcher3" class="inactive"><a href="#email" onclick="show_tab('tab-3', 'switcher3')">Email nearby users</a></li>
{% endif %}
<div class="clear"></div>
</ul>
<div class="clear"></div>
<div id="tab-1" class="tab">
    <div class="span-4">
        
        <div class="gradient-box">
            <h2>{{constituency.name}}</h2>
            <p>
             {% ifequal constituency.customuser_set.count 1 %}
               {% if volunteer_here %}
                 You're the only volunteer here so far.
               {% else %}
                 There's only one volunteer here.
               {% endif %}
             {% else %}
               There are {{constituency.customuser_set.count}} volunteers here.
             {% endifequal %}
            </p>

            <ul class="info">
                <li><label>Current MP</label> {% if constituency.current_mp.full_name %}<a href="http://www.theyworkforyou.com/mp/?p={{ constituency.current_mp.person_id }}">{{ constituency.current_mp.full_name }} ({{ constituency.current_mp.party }})</a>{% else %}None (this is a new constituency){% endif %}</li>
                <li><label>On the web</label> <a href='{{ constituency.wikipedia_url }}' target="_blank">on Wikipedia</a></li>
                <li><label>&nbsp;</label> <a href='{{ constituency.ynmp_url }}' target="_blank">on YourNextMP</a></li>
                <li><label>&nbsp;</label> <a href='http://openlylocal.com/hyperlocal_sites?location={{ constituency.name }},%20UK&commit=Search' target="_blank">nearby local websites</a></li>
            {% with constituency.issue_set.latest as latest_issue %}
                <li><label>Latest issue</label> {% if latest_issue %}<a href='#issues' onclick="show_tab('tab-2', 'switcher2')">"{{ latest_issue.question }}" from {{ latest_issue.created_by.display_name }}</a> (<a href='{% url add_issue constituency=constituency.slug %}'>add issue</a>){% else %}<a href='{% url add_issue constituency=constituency.slug %}'>no issues yet, add one!</a>{% endif %}
            {% endwith %}
            </ul>
        </div>
        
        <h4>Recent activity in {{ constituency.name }}</h4>
        {% if activity %}
            {% include "tasks/activity_list.html" %}
        {% else %}
            There has been no activity near you - be the first, do a task! Maybe you need to <a href='{% url inviteindex %}'>invite some friends</a>.
        {% endif %}
    </div>
    <div class="span-4 last">
        {% with volunteer_here as can_post %}
            {% include "constituency_comment.html" %}
        {% endwith %}

        <h3>Volunteers here</h3>
        {% with volunteer_here as show_email %}
        {% with constituency.customuser_set.all as users %}
            {% include "user_list.html" %}
        {% endwith %}
        {% endwith %}
        <!--<h3>Help us get better coverage</h3>
        <p>Any markers on this map mark the centres of nearby constituencies where we don't currently have any volunteers. If you know anyone who might live there, please {% if not request.user.is_anonymous %}<a href="/invite/">invite them</a>{% else %}invite them{% endif %} and help us get volunteers in the whole country!</p>  
        <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=http:%2F%2Fwww.democracyclub.org.uk%2Fstatistics%2Ffewerthan%2F1%2Fgeo.rss&amp;sll=&amp;sspn={{latspan}},{{lonspan}}&amp;ie=UTF8&amp;ll={{constituency.lat}},{{constituency.lon}}&amp;spn={{latspan}},{{lonspan}}&amp;z=&amp;output=embed"></iframe><br /><small><a href="http://maps.google.co.uk/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=http:%2F%2Fwww.democracyclub.org.uk%2Fstatistics%2Ffewerthan%2F1%2Fgeo.rss&amp;sll=53.800651,-4.064941&amp;sspn=16.261859,33.618164&amp;ie=UTF8&amp;ll={{constituency.lat}},{{constituency.lon}}&amp;spn={{latspan}},{{lonspan}}&amp;z=10" style="color:#0000FF;text-align:left">View Larger Map</a></small>
    {% if not request.user.is_anonymous %}
     {% include "more_constituencies_form.html" %}
    {% endif %}-->
    </div>
</div>
<div id="tab-2" class="tab">
    <h3>Local issues in {{ constituency.name }}</h3>
    <p><a href='{% url issues_page constituency=constituency.slug %}'>Printable page of issues for {{ constituency.name }}</a></p>
    <p>We're collecting local issues in {{ constituency.name }} to put to the candidates standing at the 2010 general election in the form of a questionnaire. A good local issue will be about a problem of local relevance, possibly suggesting how something should have been/be done, and be something someone can either agree or disagree with.</p>
    {% include 'issues/issue_list.html' %}
</div>
{% if request.user.is_superuser %}
<div id="tab-3" class="tab">
    <h3>Send message to users in this constituency (admin only)</h3>
    <form method="post">
        Subject: <input type="text" name="subject" /><br />
        <textarea name="message" style="width:100%; height:10em;"></textarea><br />

        Send message to people in all constituencies within
        <input name="within_km" size="3" value="50" />km of here<br />
        <input type="submit" name="value" />
    </form>    
</div>
<div id="tab-4" class="tab">
    <h3>Local questions for candidate questionnaire</h3>
    <p>These are the questions that have been made out of the local issues Demoracy Club volunteers have posted. They'll make up the 'local' section of a questionnaire that <a href='http://www.theyworkforyou.com/'>TheyWorkForYou</a> is developing in conjunction with Demoracy Club. Below the question is the local issue it's derived from.</p>
    <h4>Do you agree that ... ?</h4>
    <ul class="refined_issues">
        {% for refined_issue in constituency.refinedissue_set.all %}
            <li class="refined_issue {% cycle 'row1' 'row2' %}">{{ refined_issue.question }}{% if refined_issue.reference_url %} (<a href='{{ refined_issue.reference_url }}'>source</a>){% endif %}
                <div class="based_on">
                    {% with refined_issue.based_on as issue %}
                        Based on issue: {{ issue.question }}{% if refined_issue.reference_url %} (<a href='{{ issue.reference_url }}'>source</a>){% endif %}
                    {% endwith %}
                </div>
            </li>
        {% endfor %}
    </ul>
</div>
{% endif %}
{% endblock %}
